#include "graph.h"

#include <iostream>


bool Graph::Adjacent(int a, int b){
    for(auto edge:edges){
        int first;
        int second;
        std::tie(first, second, std::ignore) = edge;

        if((a == first and b == second) or (a == second and b == first)){
            return true;
        }
    }
    return false;
}

float Graph::Weight(int a, int b){
    for(auto edge:edges){
        int first;
        int second;
        float weight;
        std::tie(first, second, weight) = edge;

        if((a == first and b == second) or (a == second and b == first)){
            return weight;
        }
    }
    return 0;
}

std::vector<int> Graph::Neighbours(int a){
    std::vector<int> neighbours;
    for(auto edge:edges){
        int first;
        int second;
        std::tie(first, second, std::ignore) = edge;

        if(a == first){
            neighbours.push_back(second);
        }
        else if(a == second){
            neighbours.push_back(first);
        }
    }
    return neighbours;
}

void Graph::Add(int a, int b, float weight){
    if(a > b){
        int temp = a;
        a = b;
        b = temp;
    }

    if(Adjacent(a, b)){
        return;
    }

    edges.push_back(std::make_tuple(a, b, weight));
}

void Graph::Delete(int a, int b){
}

void Graph::Print(){
    for(auto edge:edges){
        int a, b, w;
        std::tie(a, b, w) = edge;
        std::cout<<"["<<a<<", "<<b<<", "<<w<<"]\n";
    }
}
